<?php

App::uses('AppController', 'Controller');

class AuthmenusController extends AppController {

    var $uses = array('Authmenu');

    public function index() {
        $this->Authmenu->recursive = 0;
        $this->set('cakeDescription', 'Menu');
        $this->set('title_for_layout', 'Index');
        $this->set('menu', 'users');
        $this->set('submenu', 'menu');
        $textsearch = "";
        if (!empty($this->data)) {
            
        }
        $this->set('authmenus', $this->paginate());
        $this->set('textsearch', $textsearch);
    }

    public function view($id = null) {
        $this->set('cakeDescription', 'Menu');
        $this->set('title_for_layout', 'View');
        $this->Authmenu->id = $id;
        if (!$this->Authmenu->exists()) {
            throw new NotFoundException(__('Invalid news'));
        }
        
        $this->set('authmenu', $this->Authmenu->read(null, $id));
        $this->set('menu', 'users');
        $this->set('submenu', 'menu');
    }

    public function add() {
        $this->set('cakeDescription', 'Menu');
        $this->set('title_for_layout', 'Add');

        if ($this->request->is('post')) {
            $this->Authmenu->create();
            if ($this->Authmenu->save($this->request->data)) {
                $this->Session->setFlash(__('The news has been saved'));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The news could not be saved. Please, try again.'));
            }
        }
        $this->set('parent_ids', $this->Authmenu->find('list', array('conditions' => array('Authmenu.parent_id' => 0), 'order' => array('Authmenu.item'))));
        $this->set('menu', 'users');
        $this->set('submenu', 'menu');
    }

    public function edit($id = null) {
        $this->set('cakeDescription', 'Menu');
        $this->set('title_for_layout', 'Edit');

        $this->Authmenu->id = $id;
        if (!$this->Authmenu->exists()) {
            throw new NotFoundException(__('Invalid news'));
        }
        if ($this->request->is('post') || $this->request->is('put')) {
            if ($this->Authmenu->save($this->request->data)) {
                $this->Session->setFlash(__('The news has been saved'));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The news could not be saved. Please, try again.'));
            }
        } else {
            $this->request->data = $this->Authmenu->read(null, $id);
        }
        $this->set('parent_ids', $this->Authmenu->find('list', array('conditions' => array('Authmenu.parent_id' => 0), 'order' => array('Authmenu.item'))));

        $this->set('menu', 'users');
        $this->set('submenu', 'menu');
    }

    public function delete($id = null) {
        if (!$this->request->is('post')) {
            throw new MethodNotAllowedException();
        }
        $this->Authmenu->id = $id;
        if (!$this->Authmenu->exists()) {
            throw new NotFoundException(__('Invalid news'));
        }
        if ($this->Authmenu->delete()) {
            $this->Session->setFlash(__('News deleted'));
            $this->redirect(array('action' => 'index'));
        }
        $this->Session->setFlash(__('News was not deleted'));
        $this->redirect(array('action' => 'index'));
    }
}